#include <iostream>
#include  "../common/ContactException.h"

#include "ContactsServer.h"

using namespace std;



void menu() 
{
    cout << endl;
    std::cout << "------------------------------------------------" << std::endl
              << "----------------  请选择对通讯录的操作  ----------------" << std::endl
              << "----------------  1、新增联系人  ----------------" << std::endl
              << "----------------  2、删除联系人  ----------------" << std::endl
              << "----------------  3、查看联系人列表  ----------------" << std::endl
              << "----------------  4、查看联系人详细信息  ----------------" << std::endl
              << "----------------  0、退出  ----------------" << std::endl
              << "------------------------------------------------" << std::endl;
    cout << endl;
}

int main()
{
    enum OPERATE {QUIT = 0,ADD, DEL, FIND_ALL, FIND_ONE};
     ContactsServer contactsServer;
    while(true)
    {
        menu();
        cout << "----> 请选择: ";
        int choose;
        cin >> choose;
        cin.ignore(256,'\n');
        
        try 
        {
            switch(choose)
            {
                case OPERATE::QUIT:
                    cout << " --> 程序退出" << endl;
                    return 0;
                case OPERATE::ADD:
                    contactsServer.addContact();
                    break;
                case OPERATE::DEL:
                    contactsServer.delContact();
                    break;
                case OPERATE::FIND_ALL:
                    contactsServer.findContacts();
                    break;
                case OPERATE::FIND_ONE:
                    contactsServer.findContact();
                    break;
                default :
                    cout << "选择error 请重新选择 " << endl;
            }
        }
        catch(const ContactException& e)
        {
            cout << "----> 操作通讯录发送异常" << endl;
            cout << "----> 异常信息： " << e.what() <<endl;
        }
        
    }
}



